﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class AdminLogin2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["AdminLogin2"] == null)
                //{
                //    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆总站！", "AdminLogin.aspx");
                //}
                //else
                //{

                //}
            }
        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
            //if (Session["AdminLogin2"] != null)
            //{


            //}
            string checkcode = this.txtCode.Text.Trim();
            if (Session["CheckCode"] != null)
            {
                if (checkcode.ToUpper() == Session["CheckCode"].ToString())
                {
                    string name = this.txt_name.Text.Trim();
                    string pwd = this.txt_pass.Text.Trim();
                    pwd = myPublic.GetMd5(pwd);

                    int webId = int.Parse(Application["webid"].ToString());

                    Session["AdminLogin2"] = webId;

                    lcmyjobs.BLL.admininfo bad = new BLL.admininfo();

                    int id = bad.AdminLogin(name, pwd, webId);

                    DataSet ds = bad.GetList(" aname='" + name + "' and apwd= '" + pwd + "'");

                    if (id != 0)
                    {
                        lcmyjobs.BLL.login_log log = new BLL.login_log();

                        lcmyjobs.Model.login_log logm = new Model.login_log();

                        logm.login_ip = Page.Request.UserHostAddress;
                        logm.login_name = name;
                        logm.login_time = DateTime.Now;

                        if (log.Add(logm) > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                Session["admin_id"] = ds.Tables[0].Rows[0]["aid"].ToString();
                            }

                            Session["adminName"] = name;
                            Response.Redirect("Frame.aspx");
                        }
                        else
                        {
                            Maticsoft.Common.MessageBox.Show(this, "登陆异常！");
                        }

                        //Session["user"] = Bp.GetModel(id);

                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "用户名或密码不对！");
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "验证码不对！");
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "验证码不对！");
            }






        }
    }
}